package com.action;

import java.util.List;

import org.apache.struts2.json.annotations.JSON;

import com.bean.Users;
import com.service.UserService;
import com.util.Page;

public class UserAction extends BasicAction {
	private UserService userService;
	private List<Users> users;   
	private Users user;
	private Page page;
	
	
	public String execute(){
		return findByQuery();
	}
	
	// 保存
	public String saveUser(){
			try {
				userService.saveBatch(users);
				return findByQuery();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				message = e.getMessage();
				return NONE;
			}
			
	}

	// 删除
	public String deleteUser() {
		userService.deleteBatch(users);
		return findByQuery();
	}
	
	//根据条件查找用户
	public String findByQuery(){
		users = userService.findByQuery(user,page);
		return NONE;
	}
    
	@JSON(serialize=false) //加上是为了不让其反序列化为json，此方法为dao接口，所以转化过程会报错
	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}
    
	public List<Users> getUsers() {
		return users;
	}
	
	public void setUsers(List<Users> users) {
		this.users = users;
	}

	public Users getUser() {
		return user;
	}

	public void setUser(Users user) {
		this.user = user;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}
    
}
